import { getCitys } from '@/api/city'

const city = {
  state: {
    citys: []
  },

  mutations: {
    SET_CITYS: (state, citys) => {
      state.citys = citys
    }
  },

  actions: {
    // 获取城市列表存起来
    GetCitys({ commit }) {
      return new Promise((resolve, reject) => {
        getCitys()
          .then((response) => {
            const data = response.data
            commit('SET_CITYS', data)
            resolve(data)
          })
          .catch((error) => {
            reject(error)
          })
      })
    }
  }
}

export default city
